<?php

// include common.php, which sets up the VidoopSecure manager ($vs)
require_once dirname(__FILE__) . '/common.php';

// get an instance of Auth_Vidoop_Secure_CaptchaService
$service = $vs->get_service('captcha');


// if the form has been submitted, check if the captcha code is correct
if (array_key_exists('submit', $_REQUEST)) {
	$valid = $service->verify_code($_REQUEST['captcha_id'], $_REQUEST['code']);
	if ($valid) {
		echo '<p>Correct! <a href="' . $_SERVER['PHP_SELF'] . '">Try another one</a></p>';
		exit;
	} else {
		echo '<p>Incorrect.  Try again.</p>';
	}
}

// display a new captcha
$captcha = $service->new_captcha();
?>
<form method="get">
	<img src="<?php echo $captcha->image; ?>" />
	<p><?php echo $captcha->text; ?></p>
	<input type="input" name="code" value="" />
	<input type="hidden" name="captcha_id" value="<?php echo $captcha->id; ?>" />
	<input type="submit" name="submit" value="Submit" />
</form>
